package tech.lq0.dreamaticvoyage.recipe;

import net.minecraft.core.NonNullList;
import net.minecraft.world.SimpleContainer;
import net.minecraftforge.fluids.FluidStack;

public class SimpleFluidContainer extends SimpleContainer {

    private final int fluidSize;
    private final NonNullList<FluidStack> fluidStacks;

    public SimpleFluidContainer(int size, int fluidSize) {
        super(size);
        this.fluidSize = fluidSize;
        this.fluidStacks = NonNullList.withSize(fluidSize, FluidStack.EMPTY);
    }

    public FluidStack getFluid(int index) {
        return index >= 0 && index < this.fluidStacks.size() ? this.fluidStacks.get(index) : FluidStack.EMPTY;
    }

    public void setFluid(int pIndex, FluidStack pStack) {
        this.fluidStacks.set(pIndex, pStack);
        this.setChanged();
    }

    public int getFluidSize() {
        return this.fluidSize;
    }

    @Override
    public void clearContent() {
        super.clearContent();
        this.fluidStacks.clear();
    }

    @Override
    public String toString() {
        return super.toString() + ", " + this.fluidStacks.stream().filter(fluidStack -> !fluidStack.isEmpty()).toList();
    }
}
